package com.fs.chatx.module.common.api;
import com.fs.chatx.core.api.R;
import com.fs.chatx.module.common.service.MinioService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/api")
public class AttachCotroller
{
    @Autowired
    private  MinioService minioService;

    /**
     * 上传文件
     * 文件名采用uuid,避免原始文件名中带"-"符号导致下载的时候解析出现异常
     * @param file 资源
     * @return R(bucketName, filename)
     */
    @SneakyThrows
    @PostMapping("/upload")
    public R upload(@RequestParam("file") MultipartFile file, HttpServletRequest request)
    {
        String fileUrl = minioService.uploadFile(file);
        return R.success(fileUrl);
    }




}
